package com.apex.system.test;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import org.junit.jupiter.api.Test;

/**
 * Apex SystemCodeGenerator
 *
 * @author Bangda Xiao
 */
public class SystemCodeGenerator {
    private String URL = "jdbc:mysql://localhost:3306/apex-cloud?useUnicode=true&useSSL=false&characterEncoding=utf8";
    private String USER = "root";
    private String PASSWORD = "xiao2000BANG";

    @Test
    public void generate() {
        FastAutoGenerator.create(URL, USER, PASSWORD)
                .globalConfig(builder -> {
                    builder.enableSwagger()
                            .outputDir("src/main/java");
                })
                .packageConfig(builder -> {
                    builder.parent("com.apex.system") // 设置父包名
                            .entity("entity") // 设置实体类包名
                            .mapper("mapper") // 设置 Mapper 接口包名
                            .service("service") // 设置 Service 接口包名
                            .serviceImpl("service.impl") // 设置 Service 实现类包名
                            .xml("mapper.xml"); // 设置 Mapper XML 文件包名
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder()
                            .enableFileOverride()
                            .enableActiveRecord()
                            .naming(NamingStrategy.underline_to_camel)
                            .columnNaming(NamingStrategy.underline_to_camel)
                            .logicDeleteColumnName("is_deleted")
                            .enableLombok()
                            .mapperBuilder().enableFileOverride();
                })
                .templateEngine(new VelocityTemplateEngine())
                .execute();
    }
}
